#!/bin/bash

cd "$(dirname $0)"

show_help() {
    echo "使用方式：$0 [--noninteractive] name {push, pull}"
    exit 1
}

EXTRA_OPTIONS="-it"
if [ "$1" = "--noninteractive" ]; then
    EXTRA_OPTIONS=""
    shift
fi

if [ $# -ne 2 ]; then
    show_help
fi

APP=$1

case "$2" in
push) ACTION=push ;;
pull) ACTION=pull ;;
*) show_help ;;
esac

docker build . -t app-sync
docker run --rm ${EXTRA_OPTIONS} \
    -v ${HOME}/.aligo/:/root/.aligo/ \
    -v ${HOME}/.bypy/:/root/.bypy/ \
    -v ${PWD}/tmp/:/app/tmp/ \
    app-sync "${APP}" "${ACTION}"
